package org.zeroes.common_prelude;

public class KahanAdder {
	
	protected double c=0;
	protected double y=0;
	protected double t=0;
	protected double sum=0;

	public void add(double v){
		
		this.y = v - this.c;
	    this.t = this.sum + this.y;
	    this.c = (this.t - this.sum) - this.y;
	    this.sum = this.t;
	    
	}
	
	public void reset(){
	       this.c = 0;
	        this.y = 0;
	        this.t = 0;
	        this.sum = 0;
	}
	
	
}
